package com.yanh.merchant.controller;


import com.yanh.merchant.dto.AppDTO;
import com.yanh.merchant.service.IAppService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yanh
 * @since 2024-06-01
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/app")
@Tag(name="商户应用管理接口",description = "商户应用管理接口")
public class AppController {

    private final IAppService appService;

    @Operation(summary = "商户创建应用",description = "商户创建应用")
    @PostMapping(value = "/merchant/apps")
    public boolean createApp(@RequestBody AppDTO app){
        return  appService.createApp(app);
    }

    @Operation(summary = "查询商户下的应用列表")
    @GetMapping(value = "/merchant/apps")
    public List<AppDTO> queryMyApps(@RequestParam("merchantId") long merchantId) {
        return appService.queryAppByMerchant(merchantId);
    }

    @Operation(summary ="根据应用id查询应用信息")
    @GetMapping(value = "/merchant/apps/{appId}")
    public AppDTO getApp(@PathVariable("appId") String appId){
        return appService.getAppById(appId);
    }
}
